home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / hity wydania / Blender 2.49b / blender-2.49b-windows.exe / $_4_ / .blender / scripts / bpymodules / blend2renderinfo.py next >
Text File  |  2009-08-31  |  3KB  |  96 lines

  1. #!/usr/bin/python
  2.  
  3. # --------------------------------------------------------------------------
  4. # ***** BEGIN GPL LICENSE BLOCK *****
  5. #
  6. # This program is free software; you can redistribute it and/or
  7. # modify it under the terms of the GNU General Public License
  8. # as published by the Free Software Foundation; either version 2
  9. # of the License, or (at your option) any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with this program; if not, write to the Free Software Foundation,
  18. # Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  19. #
  20. # ***** END GPL LICENCE BLOCK *****
  21. # --------------------------------------------------------------------------
  22.  
  23. import struct
  24.  
  25. # In Blender, selecting scenes in the databrowser (shift+f4) will tag for rendering.
  26.  
  27. # This struct wont change according to ton.
  28. # Note that the size differs on 32/64bit
  29. '''
  30. typedef struct BHead {
  31.     int code, len;
  32.     void *old;
  33.     int SDNAnr, nr;
  34. } BHead;
  35. '''
  36.  
  37.  
  38. def read_blend_rend_chunk(path):
  39.     file = open(path, 'rb')
  40.     
  41.     if file.read(len('BLENDER')) != 'BLENDER':
  42.         return []
  43.     
  44.     # 
  45.     if file.read(1) == '-':
  46.         is64bit = True
  47.     else: # '_'
  48.         is64bit = False
  49.  
  50.     if file.read(1) == 'V':
  51.         isBigEndian = True # ppc
  52.     else: # 'V'
  53.         isBigEndian = False # x86
  54.     
  55.     
  56.     # Now read the bhead chunk!!!
  57.     file.read(3) # skip the version
  58.     
  59.     scenes = []
  60.     
  61.     while file.read(4) == 'REND':
  62.     
  63.         if is64bit:        sizeof_bhead = sizeof_bhead_left = 24 # 64bit
  64.         else:            sizeof_bhead = sizeof_bhead_left = 20 # 32bit
  65.     
  66.         sizeof_bhead_left -= 4
  67.         
  68.         if isBigEndian:    rend_length = struct.unpack('>i', file.read(4))[0]
  69.         else:            rend_length = struct.unpack('<i', file.read(4))[0]
  70.         
  71.         sizeof_bhead_left -= 4
  72.         
  73.         # We dont care about the rest of the bhead struct
  74.         file.read(sizeof_bhead_left)
  75.         
  76.         # Now we want the scene name, start and end frame. this is 32bites long
  77.         
  78.         if isBigEndian:    start_frame, end_frame = struct.unpack('>2i', file.read(8))
  79.         else:            start_frame, end_frame = struct.unpack('<2i', file.read(8))
  80.         
  81.         scene_name = file.read(24)
  82.         scene_name = scene_name[ : scene_name.index('\0') ]
  83.         
  84.         scenes.append( (start_frame, end_frame, scene_name) )
  85.     return scenes
  86.  
  87. def main():
  88.     import sys
  89.     for arg in sys.argv[1:]:
  90.         if arg.lower().endswith('.blend'):
  91.             print read_blend_rend_chunk(arg)
  92.  
  93. if __name__ == '__main__':
  94.     main()
  95.  
  96.